package cn.wolfcode.trip.admin.web.controller;

import cn.wolfcode.trip.base.domain.ProductType;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductTypeService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 商品分类控制器
 */
@RequestMapping("/productType")
@Controller
public class ProductTypeController {
    @Autowired
    private IProductTypeService typeService;
    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
        model.addAttribute("result",typeService.query(qo));
        return "product/typeList";
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(ProductType type){
        JSONResult json = new JSONResult();
        try {
            typeService.saveOrUpdate(type);
        } catch (Exception e) {
            e.printStackTrace();
            json.mark(e.getMessage());
        }
        return json;
    }

    @RequestMapping("/delete")@ResponseBody
    public Object saveOrUpdate(Long id){

        JSONResult json = new JSONResult();
        try {
            typeService.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            json.mark(e.getMessage());
        }
        return json;
    }
}
